package com.dk.controller;

import com.dk.data.Result;
import com.dk.em.ResultEnum;
import com.dk.entity.DtContent;
import com.dk.service.DtContentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Api(value = "广告微服务接口")
@RequestMapping("content")
public class DtContentController {
    @Resource
    private DtContentService contentService;

    @GetMapping
    @ApiIgnore(value = "广告分类查询")
    public Result findList(){
        List<DtContent> contentList = contentService.findList();
        return Result.response(ResultEnum.SUCCESS).setData(contentList);
    }
    @PostMapping
    @ApiIgnore(value = "广告收费")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid",value = "用户id",required = true,paramType = "query"),
            @ApiImplicitParam(name = "sid",value = "商品goodsId",required = true,paramType = "query")
    })
    public Result contentCharge(@RequestParam("uid")Integer uid,
                                @RequestParam("goodsId")Integer goodsId){
        int i = contentService.contentCharge(uid,goodsId);
        return Result.response(ResultEnum.SUCCESS).setData(i);
    }
    @PostMapping("contentInsert")
    @ApiIgnore(value = "广告增加")
    @ApiImplicitParam(name = "content",value = "广告实体类",required = true,paramType = "query")
    public Result contentInsert(@RequestBody DtContent content){
        Map map = new HashMap<>();
        map =  contentService.contentInsert(content);
        return Result.response(ResultEnum.SUCCESS).setData(map);
    }

}
